<HTML>
<HEAD>
<TITLE>[Chapter 20] StringSelection </TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 15:19:04 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch20_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 20<br>java.awt.datatransfer Reference</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch20_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>StringSelection <img src="gifs/bstar.gif" alt="(New)" border=0></H1>

<H2>Name</H2>

StringSelection <img src="gifs/bstar.gif" alt="(New)" border=0>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch20-REFSECT1-AUTOID.21"></A></h2>
</DIV>


<p>
<img align=middle src="./figs/strings.gif" alt="[Graphic: Figure from the text]" width=502 height=82 border=0>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch20-REFSECT1-AUTOID.22">Description</A></h2>

<P CLASS=para>
<tt CLASS=literal>StringSelection</tt> is a "convenience" 
class that can be used for copy and paste operations on Unicode text strings. 
For example, you could place a string on the system's clipboard with 
the following code: 

<DIV CLASS=screen>
<P>
<PRE>
Clipboard c =
  Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection s = new StringSelection(
  "Be safe when you cut and paste.");
c.setContents(s, s);
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch20-REFSECT1-AUTOID.23">Class Definition</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public class java.awt.datatransfer.StringSelection
   extends java.lang.Object
   implements java.awt.datatransfer.ClipboardOwner,
         java.awt.datatransfer.Transferable {
  // Constructor
  public StringSelection(String data);
  // Instance Methods
  public synchronized Object getTransferData (DataFlavor flavor) 
    throws UnsupportedFlavorException, IOException;
  public synchronized DataFlavor[] getTransferDataFlavors();
  public boolean isDataFlavorSupported (DataFlavor flavor);
  public void lostOwnership (Clipboard clipboard, Transferable contents);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch20-REFSECT1-AUTOID.24">Constructors</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch20-REFSECT2-AUTOID.19">StringSelection</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch20-REFSECT3-AUTOID.21">public StringSelection (String data)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>data</I><br>
<DD>

<P CLASS=para>
The 
string to be placed in a clipboard. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Constructs a <tt CLASS=literal>StringSelection</tt> 
object from the given string. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch20-REFSECT1-AUTOID.25">Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch20-REFSECT2-AUTOID.20">getTransferData</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch20-REFSECT3-AUTOID.22">public synchronized Object getTransferData (DataFlavor flavor) throws UnsupportedFlavorException, IOException</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>flavor</I><br>
<DD>

<P CLASS=para>
The requested flavor 
for the returned data, which can be either <tt CLASS=literal>DataFlavor.stringFlavor</tt> 
or <tt CLASS=literal>DataFlavor.plainTextFlavor</tt>. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The string that the <tt CLASS=literal>StringSelection</tt> 
was constructed with. This is returned either as a <tt CLASS=literal>String</tt> 
object or a <tt CLASS=literal>Reader</tt> object, 
depending on the flavor requested. 

<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P CLASS=para>
<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>UnsupportedFlavorException</I><br>
<DD>

<P CLASS=para>
If the requested flavor is not supported.

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>IOException</I><br>
<DD>

<P CLASS=para>
If a <tt CLASS=literal>Reader</tt> 
representing the string could not be created. </DL>
<p>
<DT CLASS=varlistentry>Implements<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Transferable.getTransferData(DataFlavor)</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Returns the string this <tt CLASS=literal>StringSelection</tt> 
represents. This is returned either as a <tt CLASS=literal>String</tt> 
object or a <tt CLASS=literal>Reader</tt> object, 
depending on the flavor requested. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch20-REFSECT2-AUTOID.21">getTransferDataFlavors</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch20-REFSECT3-AUTOID.23">public synchronized DataFlavor[] getTransferDataFlavors()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
An array of the data flavors the <tt CLASS=literal>StringSelection</tt> 
supports. 

<p>
<DT CLASS=varlistentry>Implements<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Transferable.getTransferDataFlavors()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>DataFlavor.stringFlavor</tt> and 
<tt CLASS=literal>DataFlavor.plainTextFlavor</tt> 
are returned. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch20-REFSECT2-AUTOID.22">isDataFlavorSupported</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch20-REFSECT3-AUTOID.24">public boolean isDataFlavorSupported (DataFlavor flavor)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>flavor</I><br>
<DD>

<P CLASS=para>
The flavor in question. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>true</tt> if <tt CLASS=literal>flavor</tt> 
is supported; <tt CLASS=literal>false</tt> otherwise. 

<p>
<DT CLASS=varlistentry>Implements<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Transferable.isDataFlavorSupported(DataFlavor)</tt> </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch20-REFSECT2-AUTOID.23">lostOwnership</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch20-REFSECT3-AUTOID.25">public void lostOwnership (Clipboard clipboard, Transferable contents)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>clipboard</I><br>
<DD>

<P CLASS=para>
The clipboard whose contents are changing.

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>contents</I><br>
<DD>

<P CLASS=para>
The contents that were on the clipboard. </DL>
<p>
<DT CLASS=varlistentry>Implements<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>ClipboardOwner.lostOwnership(Clipboard, 
Transferable)</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Does nothing. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch20-REFSECT1-AUTOID.26">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>Clipboard</tt>, <tt CLASS=literal>ClipboardOwner</tt>, 
<tt CLASS=literal>DataFlavor</tt>, <tt CLASS=literal>String</tt>, 
<tt CLASS=literal>Transferable</tt> 

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch20_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch20_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>DataFlavor <img src="gifs/bstar.gif" alt="(New)" border=0></td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Transferable <img src="gifs/bstar.gif" alt="(New)" border=0></td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
